/**
 * Created by HZH
 * Date-Time: 2022-01-26
 */

import React, { useRef, useState } from 'react';
import { Button } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import { TheContainer, TheTable } from '@/components';
import { getProjectList } from '@/services/project/list'
import styles from './index.less';

const getList = async function () {
  const data = [
    {
      id: '0',
      name: '名称',
      creator: '黄忠浩',
      editor: '前端',
      desc: '描述信息',
      createTime: new Date(),
      updateTime: new Date(),
      status: '0'
    }
  ];
  return {
    data: data,
    current: 1,
    pageSize: "20",
    total: 25,
    success: true
  };
};

export default () => {
  const actionRef = useRef();
  const [selectedRowKeys, setSelectedRowKeys]  = useState([]);
  const columns = [
    {
      title: '工单号',
      dataIndex: 'projectName',
    },
    {
      title: '、设备号',
      dataIndex: 'projectName',
    },
    {
      title: '项目名称',
      dataIndex: 'projectName',
    },
    {
      title: '位置',
      dataIndex: 'creator',
      search: false,
    },
    {
      title: '线路',
      dataIndex: 'creator',
      search: false,
    },
    {
      title: '报警/预警类型',
      dataIndex: 'creator',
      search: false,
    },
    {
      title: '时间',
      dataIndex: 'createTime',
      valueType: 'dateTime',
      search: false,
    },

    {
      title: '数值',
      dataIndex: 'editor',
      search: false,
    },
    {
      title: '状态',
      dataIndex: 'editor',
      search: false,
    },
  ];

  const handleSetSelectedRowKeys = (val) => {
    setSelectedRowKeys(val)
  };

  return (
    <TheContainer>
      <TheTable
        actionRef={actionRef}
        toolBarRender={() => [
          <Button type="primary" key="primary">
            导出全部
          </Button>,
          <Button type="primary" key="primary">
            导出当前页
          </Button>,
        ]}
        columns={columns}
        request={getProjectList}
        beforeSearchSubmit={(params) => {
          console.log(params)
        }}
        rowSelection={{
          selectedRowKeys: selectedRowKeys,
          onChange: handleSetSelectedRowKeys
        }}
      />
    </TheContainer>
  );
};
